-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pyproject.toml writer #150
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #150 +/- ##
==========================================
- Coverage 96.44% 96.40% -0.04%
==========================================
Files 72 73 +1
Lines 3207 3256 +49
==========================================
+ Hits 3093 3139 +46
- Misses 114 117 +3
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@clavedeluna overall this work looks really nice but I'm adding some comments here since I didn't have the opportunity to review before this was merged.
tomlkit.dump(pyproject, f) | ||
|
||
changes = [ | ||
Change( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be factored out into the base class now since it includes some fiddly logic that will be pretty much the same for each writer.
from codemodder.dependency import DefusedXML, Security | ||
from codemodder.project_analysis.file_parsers.package_store import PackageStore | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to have a test case somewhere showing whether or not we preserve comments since this is going to be pretty important.
@@ -27,6 +28,10 @@ def write( | |||
return RequirementsTxtWriter( | |||
self.dependencies_store, self.parent_directory | |||
).write(dependencies, dry_run) | |||
case "pyproject.toml": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel pretty strongly that these kinds of values should be represented by an enum. The fact that it is being used as cases for match
really emphasizes that to me.
[f"{dep.requirement}" for dep in dependencies] | ||
) | ||
except tomlkit.exceptions.NonExistentKey: | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we probably ought to have some kind of debug logging either here or at the caller.
Overview
Add a pyproject.toml dependency writer
Description
tomlkit
to parse and update the toml file, we didn't have a way to get the line numbers that changed. For that, I created a custom function that uses the output ofdifflib.unified_diff
and parses out the@@ -x,y +a,b @@
and any+ ...
lines.